package com.zhny.project.exec.record.service.impl;

import java.util.List;
import java.util.UUID;

import com.zhny.common.utils.DateUtils;
import com.zhny.common.utils.security.ShiroUtils;
import com.zhny.project.exec.display.domain.AlgorithmDisplay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhny.project.exec.record.mapper.RecordMapper;
import com.zhny.project.exec.record.domain.Record;
import com.zhny.project.exec.record.service.IRecordService;
import com.zhny.common.utils.text.Convert;

/**
 * 数据计算记录Service业务层处理
 *
 * @author lxh
 * @date 2020-03-03
 */
@Service
public class RecordServiceImpl implements IRecordService
{
    @Autowired
    private RecordMapper recordMapper;

    /**
     * 查询数据计算记录
     *
     * @param recordKey 数据计算记录ID
     * @return 数据计算记录
     */
    @Override
    public Record selectRecordById(String recordKey)
    {
        return recordMapper.selectRecordById(recordKey);
    }

    /**
     * 查询数据计算记录列表
     *
     * @param record 数据计算记录
     * @return 数据计算记录
     */
    @Override
    public List<Record> selectRecordList(Record record)
    {
        return recordMapper.selectRecordList(record);
    }

    /**
     * 新增数据计算记录
     *
     * @param record 数据计算记录
     * @return 结果
     */
    @Override
    public int insertRecord(Record record)
    {
        record.setCreateTime(DateUtils.getNowDate());
        return recordMapper.insertRecord(record);
    }

    /**
     * 修改数据计算记录
     *
     * @param record 数据计算记录
     * @return 结果
     */
    @Override
    public int updateRecord(Record record)
    {
        record.setUpdateTime(DateUtils.getNowDate());
        return recordMapper.updateRecord(record);
    }

    /**
     * 删除数据计算记录对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteRecordByIds(String ids)
    {
        return recordMapper.deleteRecordByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除数据计算记录信息
     *
     * @param recordKey 数据计算记录ID
     * @return 结果
     */
    public int deleteRecordById(String recordKey)
    {
        return recordMapper.deleteRecordById(recordKey);
    }

    @Override
    public int storagesService(String dataFilePath, AlgorithmDisplay algorithmDisplay){
        Record record = new Record();

    //    if (algorithmDisplay.getDatarowvalue().equals("1")) {
        record.setRecordKey(UUID.randomUUID().toString());
        record.setRouteAddress(dataFilePath);
        record.setCreateBy(ShiroUtils.getUserId().toString());
        record.setRecordSign("0");
        record.setRecordId(algorithmDisplay.getAlgorithmId());
        record.setRecordShow(algorithmDisplay.getAlgorithmRoute());
        record.setRecordSpecies(algorithmDisplay.getSpecies());
        record.setRecordStage(algorithmDisplay.getStage());
        record.setRecordStarTime(algorithmDisplay.getStarTime());
        record.setRecordEndTime(algorithmDisplay.getEndTime());

        recordMapper.insertRecord(record);
        return 1;
     //   }

    /*    if (algorithmDisplay.getDatarowvalue().equals("2")) {
            record.setRecordKey(UUID.randomUUID().toString());
            record.setRouteAddress(dataFilePath);
            record.setCreateBy(ShiroUtils.getUserId().toString());
            record.setRecordId(algorithmDisplay.getAlgorithmId());
            record.setRecordShow(algorithmDisplay.getAlgorithmRoute());
            record.setRecordSign("2");
            record.setRecordSpecies(algorithmDisplay.getSpecies());
            record.setRecordStage(algorithmDisplay.getStage());
            record.setRecordStarTime(algorithmDisplay.getStarTime());
            record.setRecordEndTime(algorithmDisplay.getEndTime());

            recordMapper.insertRecord(record);
            return 1;
        }

        if (algorithmDisplay.getDatarowvalue().equals("3")) {
            record.setRecordKey(UUID.randomUUID().toString());
            record.setRouteAddress(dataFilePath);
            record.setRecordShow(algorithmDisplay.getAlgorithmRoute());
            record.setCreateBy(ShiroUtils.getUserId().toString());
            record.setRecordId(algorithmDisplay.getAlgorithmId());
            record.setRecordSign("3");
            record.setRecordSpecies(algorithmDisplay.getSpecies());
            record.setRecordStage(algorithmDisplay.getStage());
            record.setRecordStarTime(algorithmDisplay.getStarTime());
            record.setRecordEndTime(algorithmDisplay.getEndTime());

            recordMapper.insertRecord(record);
            return 1;
        }

        return 0;*/
    }

    public Record selectSave(Record record) {
        return recordMapper.selectSave(record.getRecordKey());
    }
}
